package com.intelligentclass.services;

import com.intelligentclass.entity.Collection;
import com.intelligentclass.repositories.CollectionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CollectionService {

    @Autowired
    private CollectionRepository collectionRepository;
    public CollectionService(CollectionRepository collectionRepository) {
        this.collectionRepository = collectionRepository;
    }

    public Collection saveCollection(Collection collection) {
        return collectionRepository.save(collection);
    }


    public boolean existsByCommentIdAndSno(int commentId, String sno) {
        return collectionRepository.existsByCollectionCommentIdAndCollectionSno(commentId, sno);
    }

    public List<Collection> findCollectionsBySno(String sno) {
        return collectionRepository.findByCollectionSno(sno);
    }

    public void deleteCollection(Collection collection) {
        collectionRepository.delete(collection);
    }

    public Collection findByCommentIdAndSno(int commentId, String sno) {
        return collectionRepository.findByCollectionCommentIdAndCollectionSno(commentId, sno);
    }
}